package 点名游戏;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Game extends JFrame implements MouseListener {

    JButton Begain = new JButton();

    public Game() {
        initJFrame();
        initJMenuBar();

        //让界面显示出来
        this.setVisible(true);

    }

    private void initJFrame() {
        //设置界面宽高
        this.setSize(960, 960);
        //设置界面标题
        this.setTitle("随机点名v1.0");
        //设置界面置顶(点击其他界面还在最上层)
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式(点×结束程序运行)
        this.setDefaultCloseOperation(3);//3为关一个界面程序停止(WindowConstants.EXIT_ON_CLOSE)2为关闭所有界面才停止
        //取消默认的居中放置，取消了才能实现图片的x y 轴放置
        this.setLayout(null);
    }

    private void initJMenuBar() {
        Begain.setBounds(360, 320, 240, 120);
        Begain.setText("开始点名");
        Begain.addMouseListener(this);
        this.getContentPane().add(Begain);
    }

    private void initmage() {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "李文卓", "张晓玥", "郑凯宇", "付子昂", "邝培志", "郑谦", "郑研"
                , "钱昱铮", "肖纯茹", "陈佳云", "李钰萱", "马静雯", "刘阳", "施卓凡", "邓品聪");
    Random r = new Random();
    int i = r.nextInt(1,15);
        JLabel jLabel = new JLabel(new ImageIcon("D:\\Java\\pingtuyouxi\\dianmingimage\\avatar\\avatar" + i + ".jpg"));
        jLabel.setBounds(320, 100, 320, 320);
        this.getContentPane().add(jLabel);
        this.getContentPane().repaint();
        }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getSource()==Begain){
            this.getContentPane().removeAll();
            initmage();
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}